home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.06 Oct 92 / Getting Started / IconMania in Pascal / IconMania.p next >
Encoding:
Text File  |  1992-09-08  |  1.8 KB  |  107 lines  |  [TEXT/PJMM]

  1. program Mondrian;
  2.     const
  3.         kBaseResID = 128;
  4.         kRandomUpperLimit = 32768;
  5.  
  6.  
  7. {-------------------------------->    Randomize    <---}
  8.  
  9.     function Randomize (range: INTEGER): INTEGER;
  10.         var
  11.             randomNumber: LONGINT;
  12.     begin
  13.         randomNumber := Random;
  14.         randomNumber := abs(randomNumber);
  15.  
  16.         Randomize := (randomNumber * range) div kRandomUpperLimit;
  17.     end;
  18.  
  19.  
  20. {-------------------------------->    RandomPoint    <---}
  21.  
  22.     procedure RandomPoint (var thePoint: Point);
  23.         var
  24.             window: WindowPtr;
  25.     begin
  26.         window := FrontWindow;
  27.  
  28.         thePoint.h := Randomize(window^.portRect.right - window^.portRect.left);
  29.         thePoint.v := Randomize(window^.portRect.bottom - window^.portRect.top);
  30.     end;
  31.  
  32.  
  33. {-------------------------------->    DrawRandomIcon    <---}
  34.  
  35.     procedure DrawRandomIcon (theIcon: CIconHandle);
  36.         var
  37.             p: Point;
  38.             iconRect: Rect;
  39.     begin
  40.         RandomPoint(p);
  41.  
  42.         SetRect(iconRect, p.h, p.v, p.h + 32, p.v + 32);
  43.         PlotCIcon(iconRect, theIcon);
  44.     end;
  45.  
  46.  
  47. {-------------------------------->    MainLoop    <---}
  48.  
  49.     procedure MainLoop;
  50.         var
  51.             theIcon: CIconHandle;
  52.     begin
  53.         GetDateTime(randSeed);
  54.  
  55.         theIcon := GetCIcon(kBaseResID);
  56.  
  57.         if theIcon = nil then
  58.         begin
  59.             SysBeep(10);
  60.             ExitToShell;
  61.         end;
  62.  
  63.         while (not Button) do
  64.         begin
  65.             DrawRandomIcon(theIcon);
  66.         end;
  67.     end;
  68.  
  69.  
  70. {-------------------------------->    WindowInit    <---}
  71.  
  72.     procedure WindowInit;
  73.         var
  74.             window: WindowPtr;
  75.             windowTitleH: StringHandle;
  76.     begin
  77.         window := GetNewWindow(kBaseResID, nil, WindowPtr(-1));
  78.  
  79.         if window = nil then
  80.         begin
  81.             SysBeep(10);
  82.             ExitToShell;
  83.         end;
  84.  
  85.         windowTitleH := GetString(kBaseResID);
  86.  
  87.         if windowTitleH = nil then
  88.         begin
  89.             SysBeep(10);
  90.             ExitToShell;
  91.         end;
  92.  
  93.         HLock(Handle(windowTitleH));
  94.         SetWTitle(window, windowTitleH^^);
  95.         HUnlock(Handle(windowTitleH));
  96.  
  97.         ShowWindow(window);
  98.         SetPort(window);
  99.     end;
  100.  
  101.  
  102. {-------------------------------->    Mondrian    <---}
  103.  
  104. begin
  105.     WindowInit;
  106.     MainLoop;
  107. end.